package com.fili.core;

import com.fili.core.params.DryConfig;
import com.fili.core.params.DryParams;
import com.fili.core.serial.SerialConsumer;
import com.fili.core.serial.SerialParser;
import com.fili.core.serial.SerialReader;
import com.fili.core.storage.DataStore;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Oct 29, 2006
 * Time: 10:51:57 AM
 */
public class DataCenter
{
    private static DataCenter _this;

    private SerialReader serialReader;
    private SerialParser serialParser;
    private SerialConsumer[] consumers;


    private DataCenter()
    {
        serialParser = new SerialParser();
        consumers = new SerialConsumer[DryConfig.getConfig().getEncodedPermission().nrUsc];
        for (int i = 0; i < consumers.length; i++)
        {
            consumers[i] = new SerialConsumer(new DataStore(i,DryParams.getParams().getStorePath(i)));
            serialParser.addSerialConsumer(consumers[i]);
        }
        serialReader = new SerialReader(serialParser);
    }

    public static DataCenter getDataCenter()
    {
        if (_this == null)
        {
            _this = new DataCenter();
        }

        return _this;
    }

    public SerialConsumer getConsumer(int index)
    {
        if ((index >= 0) && (index < consumers.length))
            return consumers[index];

        return null;
    }
}
